package com.bleeth.fx.helper;

import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;


/**
 * @author ：Bleeth
 * @date ：2021-11-12
 * @description：效果工具
 */
public class EffectHelper {


    public static Ds ds(Region region) {
        return new Ds(region);
    }


    /**
     * DropShadow Effect
     */
    public static class Ds {
        private Region region;

        private double radius;
        private double offsetX;
        private double offsetY;
        private double spread;
        private String color;
        private BlurType blurType;

        public Ds(Region region) {
            this.region = region;
        }

        public Ds color(String color) {
            this.color = color;
            return this;
        }

        public Ds Spread(double spread) {
            this.spread = spread;
            return this;
        }

        public Ds offsetY(double offsetY) {
            this.offsetY = offsetY;
            return this;
        }

        public Ds offsetX(double offsetX) {
            this.offsetX = offsetX;
            return this;
        }

        public Ds radius(double radius) {
            this.radius = radius;
            return this;
        }

        public Ds radius(BlurType blurType) {
            this.blurType = blurType;
            return this;
        }

        public DropShadow make() {
            DropShadow dropShadow;
            if (blurType == null) {
                dropShadow = new DropShadow(blurType, Color.web(color), radius, spread, offsetX, offsetY);
            } else {
                dropShadow = new DropShadow(radius, offsetX, offsetY, Color.web(color));
            }
            region.setEffect(dropShadow);
            return dropShadow;
        }
    }


}
